//
//  IMAAppDelegate.m
//  TIMChat
//
//  Created by AlexiChen on 16/2/26.
//  Copyright © 2016年 AlexiChen. All rights reserved.
//

#import "IMAAppDelegate.h"
#import <TencentOpenAPI/TencentOAuth.h>
//#import "WXApi.h"
//#import "TLSUI/TLSUI.h"
#import "TLSSDK/TLSRefreshTicketListener.h"
#import "TLSSDK/TLSOpenLoginListener.h"

@implementation IMAAppDelegate

void uncaughtExceptionHandler(NSException*exception){
    DebugLog(@"CRASH: %@", exception);
    DebugLog(@"Stack Trace: %@",[exception callStackSymbols]);
}

- (void)configAppLaunchWithOptions:(NSDictionary *)launchOptions
{
    [super configAppLaunchWithOptions:launchOptions];
    [[IMAPlatform sharedInstance] configOnAppLaunch];
}



- (void)applicationDidEnterBackground:(UIApplication *)application
{
    __block UIBackgroundTaskIdentifier bgTaskID;
    bgTaskID = [application beginBackgroundTaskWithExpirationHandler:^ {
        [application endBackgroundTask: bgTaskID];
        bgTaskID = UIBackgroundTaskInvalid;
    }];
    [[IMAPlatform sharedInstance] configOnAppEnterBackground];
    

}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    [[IMAPlatform sharedInstance] configOnAppEnterForeground];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [[IMAPlatform sharedInstance] configOnAppDidBecomeActive];
}


-(void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    [[IMAPlatform sharedInstance] configOnAppRegistAPNSWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
    DebugLog(@"didFailToRegisterForRemoteNotificationsWithError:%@", error.localizedDescription);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    // 处理推送消息
    
    DebugLog(@"userinfo:%@",userInfo);
    DebugLog(@"收到推送消息:%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]);
}


// 进入登录界面
// 用户可重写
- (void)enterLoginUI
{
//    IMALoginViewController *vc = [[IMALoginViewController alloc] init];
//    self.window.rootViewController = vc;
    
}


//==================================
// URL Scheme处理
- (BOOL)application:(UIApplication*)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    
    
    if ([OpenShare handleOpenURL:url]) {
        return YES;
    }else
    {
        return NO;
    }
    
    return YES;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    if ([OpenShare handleOpenURL:url]) {
        return YES;
    }else
    {
        return NO;
    }
    
    return YES;
}



@end
